= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 A u t h o r :   Y o u n g w o o k   K i m   ( K o r e a n ) 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 C o n t a c t :   r u m i a 0 6 0 1 @ g m a i l . c o m 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
   p  T! 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 ,     t    D  t  JŔ.   t,   t  \  ܭYD   X$  \.   t,   t  \@  t  .   ܭY@  X:   5 x 5   2 (  0  h  ],   @  ]X  |  8,   T  ι@  X  ]D  t  t!   t|t  H P    X  $t|t,   H P   \.     L  L  8|  \  \  2 (  0t  $!    貈  X̹  t  ҠѬ    ̹䴴      ǔ  t.    ,   2 (  0D  ̹  %t|  \.   Ż?   Ƭ    pt0( 0 (  0  L)   P  ( 1 (  0  L) D  %XՔ  D  L    .   2 (  0@  ƌ  X՘̹  T   t  . 
 
 
 
 . .   i m a g e : :   A d v a n c e d O u t p u t A l p h a 1 . g i f 
 
       : c l a s s :   i n l i n e d - r i g h t 
 
 
 
 . .   c o d e - b l o c k : :   p y t h o n 
 
       : l i n e n o s : 
 
 
 
       i m p o r t   s y s ,   p y g a m e 
 
       p y g a m e . i n i t ( ) 
 
 
 
       s i z e   =   w i d t h ,   h e i g h t   =   3 2 0 ,   2 4 0 
 
       s p e e d   =   [ 2 ,   2 ] 
 
       b l a c k   =   0 ,   0 ,   0 
 
 
 
       s c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( s i z e ) 
 
 
 
       b a l l   =   p y g a m e . i m a g e . l o a d ( " A d v a n c e d O u t p u t A l p h a 1 . g i f " ) 
 
       b a l l r e c t   =   b a l l . g e t _ r e c t ( ) 
 
 
 
       w h i l e   1 : 
 
               f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                       i f   e v e n t . t y p e   = =   p y g a m e . Q U I T :   s y s . e x i t ( ) 
 
 
 
               b a l l r e c t   =   b a l l r e c t . m o v e ( s p e e d ) 
 
               i f   b a l l r e c t . l e f t   <   0   o r   b a l l r e c t . r i g h t   >   w i d t h : 
 
                       s p e e d [ 0 ]   =   - s p e e d [ 0 ] 
 
               i f   b a l l r e c t . t o p   <   0   o r   b a l l r e c t . b o t t o m   >   h e i g h t : 
 
                       s p e e d [ 1 ]   =   - s p e e d [ 1 ] 
 
 
 
               s c r e e n . f i l l ( b l a c k ) 
 
               s c r e e n . b l i t ( b a l l ,   b a l l r e c t ) 
 
               p y g a m e . d i s p l a y . f l i p ( ) 
 
 
 
 . .   i m a g e : :   A d v a n c e d O u t p u t A l p h a 2 . g i f 
 
       : c l a s s :   i n l i n e d - r i g h t 
 
 
 
 . .   c o d e - b l o c k : :   p y t h o n 
 
       : l i n e n o s : 
 
 
 
       i m p o r t   s y s ,   p y g a m e 
 
       p y g a m e . i n i t ( ) 
 
 
 
       s i z e   =   w i d t h ,   h e i g h t   =   3 2 0 ,   2 4 0 
 
       s p e e d   =   [ 2 ,   2 ] 
 
       b l a c k   =   0 ,   0 ,   0 
 
 
 
       s c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( s i z e ) 
 
 
 
       b a l l   =   p y g a m e . i m a g e . l o a d ( " A d v a n c e d O u t p u t A l p h a 2 . g i f " ) 
 
       b a l l r e c t   =   b a l l . g e t _ r e c t ( ) 
 
 
 
       w h i l e   1 : 
 
               f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                       i f   e v e n t . t y p e   = =   p y g a m e . Q U I T :   s y s . e x i t ( ) 
 
 
 
               b a l l r e c t   =   b a l l r e c t . m o v e ( s p e e d ) 
 
               i f   b a l l r e c t . l e f t   <   0   o r   b a l l r e c t . r i g h t   >   w i d t h : 
 
                       s p e e d [ 0 ]   =   - s p e e d [ 0 ] 
 
               i f   b a l l r e c t . t o p   <   0   o r   b a l l r e c t . b o t t o m   >   h e i g h t : 
 
                       s p e e d [ 1 ]   =   - s p e e d [ 1 ] 
 
 
 
               s c r e e n . f i l l ( b l a c k ) 
 
               s c r e e n . b l i t ( b a l l ,   b a l l r e c t ) 
 
               p y g a m e . d i s p l a y . f l i p ( ) 
 
 
 
 . .   i m a g e : :   A d v a n c e d O u t p u t A l p h a 3 . g i f 
 
       : c l a s s :   i n l i n e d - r i g h t 
 
 
 
 . .   c o d e - b l o c k : :   p y t h o n 
 
       : l i n e n o s : 
 
 
 
       i m p o r t   s y s ,   p y g a m e 
 
       p y g a m e . i n i t ( ) 
 
 
 
       s i z e   =   w i d t h ,   h e i g h t   =   3 2 0 ,   2 4 0 
 
       s p e e d   =   [ 2 ,   2 ] 
 
       b l a c k   =   0 ,   0 ,   0 
 
 
 
       s c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( s i z e ) 
 
 
 
       b a l l   =   p y g a m e . i m a g e . l o a d ( " A d v a n c e d O u t p u t A l p h a 3 . g i f " ) 
 
       b a l l r e c t   =   b a l l . g e t _ r e c t ( ) 
 
 
 
       w h i l e   1 : 
 
               f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                       i f   e v e n t . t y p e   = =   p y g a m e . Q U I T :   s y s . e x i t ( ) 
 
 
 
               b a l l r e c t   =   b a l l r e c t . m o v e ( s p e e d ) 
 
               i f   b a l l r e c t . l e f t   <   0   o r   b a l l r e c t . r i g h t   >   w i d t h : 
 
                       s p e e d [ 0 ]   =   - s p e e d [ 0 ] 
 
               i f   b a l l r e c t . t o p   <   0   o r   b a l l r e c t . b o t t o m   >   h e i g h t : 
 
                       s p e e d [ 1 ]   =   - s p e e d [ 1 ] 
 
 
 
               s c r e e n . f i l l ( b l a c k ) 
 
               s c r e e n . b l i t ( b a l l ,   b a l l r e c t ) 
 
               p y g a m e . d i s p l a y . f l i p ( ) 
 
 
 
 g e n e r a t e b o a r d   h  4\  ̹䴴  2 (  0  h  ],   @  ]X  |  X\.   $`  DՔ  .   \,   p r i n t b o a r d   h  1 (  0Ř  2 (5  0D  %\.   %  @  b o a r d [ i ] [ j ]    1 x  D̲    0|  |.   t  @    %  t.   LP|  ̬X$t  X  l0|     ȴ  l0|  Ĭt|  t  ɝɠ    .   tǃ@  d\  	\   \,   tǌ    1  (     G U I t̹  Tܴ  1@  C U I )   L8t. 
 
 
 
 ,   t  l\  @   X     ι.   D  t  |\  t?   tp  $|  L  LD  #<t?     \D  #<t?   tp  $|  L    |  #<t?   D  T  lЌ  X  D  T  䲑ň  #t?   t  x0јtǤ|     F l o o d - i t D  l\t?   l\  t  X0  L8   ɔ  ι. 
 
 
 
 < 8  Tܴ>   : : 
 
 
 
         i m p o r t   p y g a m e ,   s y s ,   r a n d o m 
 
         f r o m   p y g a m e . l o c a l s   i m p o r t * 
 
         
 
         m a x H P   =   1 0   
 
         w h i t e   =   ( 2 5 5 , 2 5 5 , 2 5 5 ) 
 
         g r a y   =   ( 1 2 7 , 1 2 7 , 1 2 7 ) 
 
         b l a c k   =   ( 0 , 0 , 0 ) 
 
         r e d   =   ( 2 5 5 , 0 , 0 ) 
 
         g r e e n   =   ( 0 , 2 5 5 , 0 ) 
 
         b l u e   =   ( 0 , 0 , 2 5 5 ) 
 
         p y g a m e . i n i t ( ) 
 
         p y g a m e . d i s p l a y . s e t _ c a p t i o n ( " R e d   o r   B l a c k   P r o j e c t " ) 
 
         w i d t h   =   6 4 0   
 
         h e i g h t   =   4 8 0 
 
         m y S c r e e n   =   p y g a m e . d i s p l a y . s e t _ m o d e ( ( w i d t h ,   h e i g h t ) ) 
 
         m y T e x t F o n t   =   p y g a m e . f o n t . F o n t ( " H o o n W h i t e c a t R . t t f " ,   3 2 ) 
 
         m y T e x t   =   m y T e x t F o n t . r e n d e r ( ( s t r ( m a x H P )   +   " / "   +   s t r ( m a x H P ) ) ,   T r u e ,   r e d ,   g r a y ) 
 
         m y T e x t A r e a   =   m y T e x t . g e t _ r e c t ( ) 
 
         m y T e x t A r e a . c e n t e r   =   ( w i d t h / 2 ,   h e i g h t / 2 ) 
 
         f p s C l o c k   =   p y g a m e . t i m e . C l o c k ( ) 
 
         
 
         d e f   m a i n ( ) : 
 
                 H P   =   5 
 
                 b o a r d ,   b _ r e d ,   b _ b l a c k   =   g e n e r a t e B o a r d ( 5 , 5 )   # 1 
 
                 
 
                 w h i l e   T r u e : 
 
                         m y T e x t   =   m y T e x t F o n t . r e n d e r ( ( s t r ( H P )   +   " / "   +   s t r ( m a x H P ) ) ,   T r u e ,   r e d ,   g r a y ) 
 
                 
 
                         m y S c r e e n . f i l l ( g r a y ) 
 
         
 
                         m y S c r e e n . b l i t ( m y T e x t ,   m y T e x t A r e a ) 
 
                         d r a w H P ( H P ) 
 
                         d r a w B u t t o n s ( ) 
 
                         d r a w B o a r d ( b o a r d )   # 2 
 
         
 
                         f o r   e v e n t   i n   p y g a m e . e v e n t . g e t ( ) : 
 
                                 i f   e v e n t . t y p e   = =   Q U I T : 
 
                                         p y g a m e . q u i t ( ) 
 
                                         s y s . e x i t ( ) 
 
                                         
 
                                 e l i f   e v e n t . t y p e   = =   K E Y D O W N : 
 
                                         i f   e v e n t . k e y   = =   K _ U P : 
 
                                                 i f   H P   ! =   1 0 : 
 
                                                         H P   =   H P   +   1 
 
                                         e l i f   e v e n t . k e y   = =   K _ D O W N : 
 
                                                 i f   H P   ! =   0 : 
 
                                                         H P   =   H P   -   1 
 
                                 e l i f   e v e n t . t y p e   = =   M O U S E B U T T O N U P : 
 
                                         x ,   y   =   e v e n t . p o s 
 
                                         
 
                                         i f   p y g a m e . R e c t ( 2 7 0 ,   4 2 5 ,   4 5 ,   4 5 ) . c o l l i d e p o i n t ( x ,   y ) :   # 3 
 
                                                 i f   b _ r e d   > =   b _ b l a c k : 
 
                                                         i f   H P   ! =   1 0 : 
 
                                                                 H P   =   H P   +   1 
 
                                                         b o a r d ,   b _ r e d ,   b _ b l a c k   =   g e n e r a t e B o a r d ( 5 , 5 ) 
 
                                                 e l i f   b _ r e d   <   b _ b l a c k : 
 
                                                         i f   H P   ! =   0 : 
 
                                                                 H P   =   H P   -   1 
 
                                                         b o a r d ,   b _ r e d ,   b _ b l a c k   =   g e n e r a t e B o a r d ( 5 , 5 ) 
 
                                                         
 
                                         e l i f   p y g a m e . R e c t ( 3 2 5 ,   4 2 5 ,   4 5 ,   4 5 ) . c o l l i d e p o i n t ( x ,   y ) :   # 4 
 
                                                 i f   b _ r e d   < =   b _ b l a c k : 
 
                                                         i f   H P   ! =   1 0 : 
 
                                                                 H P   =   H P   +   1 
 
                                                         b o a r d ,   b _ r e d ,   b _ b l a c k   =   g e n e r a t e B o a r d ( 5 , 5 ) 
 
                                                 e l i f   b _ r e d   >   b _ b l a c k : 
 
                                                         i f   H P   ! =   0 : 
 
                                                                 H P   =   H P   -   1 
 
                                                         b o a r d ,   b _ r e d ,   b _ b l a c k   =   g e n e r a t e B o a r d ( 5 , 5 ) 
 
                 
 
                         p y g a m e . d i s p l a y . u p d a t e ( ) 
 
                         f p s C l o c k . t i c k ( 6 0 ) 
 
         
 
         d e f   d r a w H P ( H P ) : 
 
                 r   =   i n t ( ( h e i g h t   -   4 0 )   /   m a x H P ) 
 
         
 
                 p y g a m e . d r a w . r e c t ( m y S c r e e n ,   g r a y ,   ( 2 0 ,   2 0 ,   2 0 ,   2 0   +   ( ( m a x H P   -   0 . 5 )   *   r ) ) ) 
 
         
 
                 f o r   i   i n   r a n g e ( m a x H P ) : 
 
                         i f   H P   > =   ( m a x H P   -   i ) : 
 
                                 p y g a m e . d r a w . r e c t ( m y S c r e e n ,   b l u e ,   ( 2 0 ,   2 0   +   ( i   *   r ) ,   2 0 ,   r ) ) 
 
                         p y g a m e . d r a w . r e c t ( m y S c r e e n ,   w h i t e ,   ( 2 0 ,   2 0   +   ( i   *   r ) ,   2 0 ,   r ) ,   1 ) 
 
         
 
                 r e t u r n 
 
         
 
         d e f   d r a w B u t t o n s ( ) : 
 
                 r   =   4 5 
 
                 r _ m a r g i n   =   1 0 
 
                 c o l o r s   =   [ r e d ,   b l a c k ] 
 
                 
 
                 n u m   =   2 
 
                 m a r g i n   =   i n t ( ( w i d t h   -   ( ( r   *   n u m )   +   ( r _ m a r g i n   *   ( n u m   -   1 ) ) ) )   /   2 ) 
 
                 
 
                 f o r   i   i n   r a n g e ( 0 ,   n u m ) : 
 
                         l e f t   =   m a r g i n   +   ( i   *   r )   +   ( i   *   r _ m a r g i n ) 
 
                         u p   =   h e i g h t   -   r   -   1 0 
 
                         p y g a m e . d r a w . r e c t ( m y S c r e e n ,   c o l o r s [ i ] ,   ( l e f t ,   u p ,   r ,   r ) ) 
 
                         p y g a m e . d r a w . r e c t ( m y S c r e e n ,   g r a y ,   ( l e f t   +   2 ,   u p   +   2 ,   r   -   4 ,   r   -   4 ) ,   2 )         
 
         
 
         d e f   g e n e r a t e B o a r d ( w i d t h ,   h e i g h t ) :   # 5 
 
                 b o a r d   =   [ ] 
 
                 b _ r e d   =   0 
 
                 b _ b l a c k   =   0 
 
                 
 
                 f o r   x   i n   r a n g e ( w i d t h ) : 
 
                         c o l u m n   =   [ ] 
 
                         f o r   y   i n   r a n g e ( h e i g h t ) : 
 
                                 c o l u m n . a p p e n d ( r a n d o m . r a n d i n t ( 0 ,   1 ) ) 
 
                         b o a r d . a p p e n d ( c o l u m n ) 
 
         
 
                 f o r   x   i n   r a n g e ( w i d t h ) : 
 
                         f o r   y   i n   r a n g e ( h e i g h t ) : 
 
                                 i f ( b o a r d [ x ] [ y ]   = =   1 ) : 
 
                                           b _ r e d   =   b _ r e d   +   1 
 
                                 e l i f ( b o a r d [ x ] [ y ]   = =   0 ) : 
 
                                         b _ b l a c k   =   b _ b l a c k   +   1 
 
                         
 
                 r e t u r n   b o a r d ,   b _ r e d ,   b _ b l a c k 
 
         
 
         d e f   d r a w B o a r d ( b o a r d ) :   # 6 
 
                 r   =   5 0 
 
                 b _ w i d t h   =   5 
 
                 b _ h e i g h t   =   5 
 
                 l _ m a r g i n   =   i n t ( ( w i d t h   -   ( b _ w i d t h   *   r ) )   /   2 ) 
 
                 u _ m a r g i n   =   i n t ( ( h e i g h t   -   ( b _ h e i g h t   *   r ) )   /   2 ) 
 
         
 
                 f o r   x   i n   r a n g e ( 5 ) : 
 
                         f o r   y   i n   r a n g e ( 5 ) : 
 
                                 l e f t   =   x   *   r   +   l _ m a r g i n 
 
                                 u p   =   y   *   r   +   u _ m a r g i n 
 
                                 i f   b o a r d [ x ] [ y ]   = =   1 : 
 
                                         c o l o r   =   r e d ; 
 
                                 e l i f   b o a r d [ x ] [ y ]   = =   0 : 
 
                                         c o l o r   =   b l a c k 
 
                                 p y g a m e . d r a w . r e c t ( m y S c r e e n ,   c o l o r ,   ( l e f t ,   u p ,   r ,   r ) ) 
 
                                 
 
                 l e f t   =   l _ m a r g i n 
 
                 u p   =   u _ m a r g i n 
 
                 p y g a m e . d r a w . r e c t ( m y S c r e e n ,   w h i t e ,   ( l e f t - 1 ,   u p - 1 ,   r   *   5   +   1 ,   r   *   b _ h e i g h t   +   1 ) ,   1 ) 
 
         
 
         i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' : 
 
                 m a i n ( ) 
 
         